package com.xzssmk.leisure.x.controller;

import java.util.List;

import javax.servlet.http.HttpServletRequest;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.ModelAttribute;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestMethod;
import org.springframework.web.bind.annotation.RequestParam;
import org.springframework.web.bind.annotation.RestController;
import org.springframework.web.servlet.ModelAndView;

import com.alibaba.fastjson.JSONObject;
import com.xzssmk.leisure.x.po.ScenicSpot;
import com.xzssmk.leisure.x.service.ScenicSpotService;
import com.xzssmk.leisure.x.util.DataTables;

@RestController
@RequestMapping("scenicSpot")
public class ScenicSpotController {

    @Autowired
    private ScenicSpotService scenicSpotService;

    @RequestMapping(value = "/add", method = RequestMethod.POST, produces = "application/json; charset=utf-8")
    public String add(ScenicSpot scenicSpot) {
        return JSONObject.toJSONString(scenicSpotService.add(scenicSpot));
    }

    @RequestMapping(value = "/update", method = RequestMethod.POST, produces = "application/json; charset=utf-8")
    public String updateRole(@ModelAttribute ScenicSpot scenicSpot) {
        return JSONObject.toJSONString(scenicSpotService.update(scenicSpot));
    }

    @RequestMapping(value = "/getScenicSpot", method = RequestMethod.POST, produces = "application/json; charset=utf-8")
    public String getById(Integer id) {
        return JSONObject.toJSONString(scenicSpotService.getById(id));
    }

    @RequestMapping(value = "/delete", method = RequestMethod.POST, produces = "application/json; charset=utf-8")
    public Object delete(@RequestParam("idlist[]") List<Integer> idlist) {
        return JSONObject.toJSONString(scenicSpotService.delete(idlist));
    }

    @RequestMapping(value = "/getPageList", method = RequestMethod.POST, produces = "application/json; charset=utf-8")
    public String getPageList(HttpServletRequest request) {
        return JSONObject.toJSONString(scenicSpotService.getPageList(DataTables.getInstance(request, null)));
    }

    @RequestMapping(value = "/getUserPageList", method = RequestMethod.POST, produces = "application/json; charset=utf-8")
    public String getUserPageList(HttpServletRequest request) {
        return JSONObject.toJSONString(scenicSpotService.getUserPageList(DataTables.getInstance(request, null)));
    }

    @RequestMapping(value = "/getSelectList", method = RequestMethod.POST, produces = "application/json; charset=utf-8")
    public String getSelectList() {
        return JSONObject.toJSONString(scenicSpotService.getSelectList());
    }

    @RequestMapping(value = "/scenicSpot-list.html")
    public ModelAndView scenicSpot() {
        ModelAndView modelAndView = new ModelAndView();
        modelAndView.setViewName("scenicSpot-list");
        return modelAndView;
    }

    @RequestMapping(value = "/scenicSpot-add.html")
    public ModelAndView addScenicSpot() {
        ModelAndView modelAndView = new ModelAndView();
        modelAndView.setViewName("scenicSpot-add");
        return modelAndView;
    }

    /**
     * 商户登录管理
     */
    @RequestMapping("/user-scenicSpot-list.html")
    public ModelAndView proportion() {
        ModelAndView modelAndView = new ModelAndView();
        modelAndView.setViewName("user-scenicSpot-list");
        return modelAndView;
    }

    @RequestMapping(value = "/user-scenicSpot-update.html")
    public ModelAndView updateUserScenicSpot() {
        ModelAndView modelAndView = new ModelAndView();
        modelAndView.setViewName("user-scenicSpot-update");
        return modelAndView;
    }
}
